package org.example.k8s_cloudplatform.K8S_mapper;

import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Namespace;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.*;

import org.example.k8s_cloudplatform.utils.K8S_util;
import org.springframework.stereotype.Repository;

@Repository
public class NamespaceMapper {
    private final CoreV1Api coreApi = K8S_util.coreApi;

    public V1Namespace create(String name) throws ApiException {
        V1Namespace res;
        V1Namespace namespace=new V1Namespace();
        namespace.setMetadata(new V1ObjectMeta().name(name));
        res = coreApi.createNamespace(namespace, null, null, null);
        return res;
    }

    public void delete(String name) throws ApiException {
        V1DeleteOptions deleteOptions=new V1DeleteOptions();
        deleteOptions.setPropagationPolicy("Foreground");
        coreApi.deleteNamespace(name, null, null, null, null, null, deleteOptions);
    }


}
